//
//  LoginViewController.m
//  ZYTS-iPhone
//
//  Created by yuzhou on 12-12-13.
//  Copyright (c) 2012年 wzyk. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    backButton.hidden = !_needLogin;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [usernameField resignFirstResponder];
    [passwordField resignFirstResponder];
    return YES;
}

- (IBAction)commitLogin:(id)sender
{
    [usernameField resignFirstResponder];
    [passwordField resignFirstResponder];
    
    if (usernameField.text.length && passwordField.text.length) {
        [[AuthorManager defaultManager] loginWithUsername:usernameField.text password:passwordField.text];
    }
    else {
        ABPromptView *promptView = [[[ABPromptView alloc] initWithTitle:@"请填写用户名或密码"] autorelease];
        [promptView show];
    }
}

- (IBAction)showRegisterView:(id)sender
{
    RegisterViewController *registerViewController = [[[RegisterViewController alloc] initWithNibName:@"RegisterViewController" bundle:nil] autorelease];
    
//    UINavigationController *navController = (UINavigationController *)self.view.window.rootViewController;
    [self.navigationController pushViewController:registerViewController animated:YES];
}

- (IBAction)getBackPassword:(id)sender
{
    NSString *url = @"http://www.183read.com";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}

- (IBAction)navBack:(id)sender
{
    [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [usernameField release];
    [passwordField release];
    [backButton release];
    [super dealloc];
}
- (void)viewDidUnload
{
    [usernameField release];
    usernameField = nil;
    [passwordField release];
    passwordField = nil;
    [backButton release];
    backButton = nil;
    [super viewDidUnload];
}
@end
